package com.eregg.learn.netty.demo.pipeline;

import com.eregg.learn.netty.demo.pipeline.handler.*;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

public class NettyServer {
    public static void main(String[] args) {
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        NioEventLoopGroup boss = new NioEventLoopGroup();
        NioEventLoopGroup worker = new NioEventLoopGroup();

        serverBootstrap
                .group(boss, worker)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception {
                        nioSocketChannel.pipeline().addLast(new ServerInHandlerA());
                        nioSocketChannel.pipeline().addLast(new ServerInHandlerB());
                        nioSocketChannel.pipeline().addLast(new ServerInHandlerC());

                        nioSocketChannel.pipeline().addLast(new ServerOutHandlerA());
                        nioSocketChannel.pipeline().addLast(new ServerOutHandlerB());
                        nioSocketChannel.pipeline().addLast(new ServerOutHandlerC());
                    }
                });

        serverBootstrap.bind(8000);
    }
}
